<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				<picker mode="date" :value="date" @change="dateChange">
					{{date}} 作业
				</picker>
			</block>
		</cu-custom>
		<a-fixed :height="40">
			<a-tabs @click="inquire" :row="status.length" type="border" :value="status"></a-tabs>
		</a-fixed>
		<a-scroll :request="get" ref="aScroll" :parm='{pageSize:30}'>
			<template #item="{row:x,index}">
				<a-list :value="x" :url="`./details?id=${x.id}`"></a-list>
			</template>
		</a-scroll>
	</view>
</template>

<script>
	import {
		format
	} from "@/a/utils/api";
	export default {
		//上拉触底
		onReachBottom() {
			this.$refs.aScroll.lower();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.aScroll.get(true).then(res => {
				uni.stopPullDownRefresh();
			});
		},
		data() {
			return {
				date: format(new Date(), "yyyy-MM-dd"),
				status: [{
						type: "",
						name: "全部"
					}, {
						type: "NO_SUBMIT",
						name: "待提交"
					},
					{
						type: "SUBMITTED",
						name: "已提交"
					},
					{
						type: "PASS",
						name: "通过"
					},
					{
						type: "NO_PASS",
						name: "未通过"
					}
				],
				tabsParm: {
					type: "",
					name: "全部"
				},
			}
		},
		methods: {
			get(parm = {}) {
				return this.$http.get('/api/v1/works/queryByToken', {
				}).then(res => {
					return {
						total: res.totalSize,
						data: res.results.map(x => {
							return {
								...x,
								name: x.title,
								// sonTitle: x.content,
								phone: format(x.createTime),
								img: require('./1.png')
							}
						})
					}
				});
				
				// return this.$http.post('/api/v1/works/findWorksPage', {
				// 	...parm,
				// 	...this.tabsParm,
				// 	...this.$store.state.userInfo,
				// 	startTime: this.date
				// }).then(res => {
				// 	return {
				// 		total: res.totalSize,
				// 		data: res.results.map(x => {
				// 			return {
				// 				...x,
				// 				name: x.title,
				// 				// sonTitle: x.content,
				// 				phone: format(x.createTime),
				// 				img: require('./1.png')
				// 			}
				// 		})
				// 	}
				// });

				const data = new Array(15).fill({
					name: "语文",
					sonTitle: "默写将进酒全文",
					phone: "已耗时16分钟",
					img: require('./1.png')
				});
				console.log('请求：' + JSON.stringify({
					...parm,
					...this.tabsParm,
					date: this.date
				}));
				return new Promise(r => {
					setTimeout(e => {
						r({
							total: 200,
							data
						})
					}, 1000);
				});
			},
			inquire(e) {
				this.tabsParm = e;
				this.$refs.aScroll.get(true);
			},
			dateChange({
				detail: {
					value
				}
			}) {
				this.date = value;
				this.$refs.aScroll.get(true);
			},
		}
	}
</script>

<style>

</style>
